home *** CD-ROM | disk | FTP | other *** search
File List | 1989-12-13 | 11.6 KB | 503 lines |
- _C PRINTER FOR VMS AND UNIX_
- by Kevin E. Poole
-
- SIDEBAR TO _AUTOMATIC MODULE CONTROL REVISITED_ BY RON WINTER
-
- [LISTING ONE]
-
- !
- ! VAX/VMS MMS Description File
- !
- ! DEFINITIONS:
- H = cpheader.h
- !
- ! CP
- !
- cp DEPENDS_ON cp.obj cpbuild.obj cpfuncts.obj cpinput.obj
- LINK/EXEC=cp cp.obj,cpbuild.obj,cpfuncts.obj,cpinput.obj
- PURGE *.obj, *.exe
-
- cp.obj DEPENDS_ON $(H) cp.c
- cc cp.c
-
- cpbuild.obj DEPENDS_ON $(H) cpbuild.c
- cc cpbuild.c
-
- cpfuncts.obj DEPENDS_ON $(H) cpfuncts.c
- cc cpfuncts.c
-
- cpinput.obj DEPENDS_ON $(H) cpinput.c
- cc cpinput.c
-
-
- [LISTING TWO]
-
- #
- # VAX/Unix Makefile
- #
- # DEFINITIONS:
- #
- H = cpheader.h
- #
- # CP
- #
- cp : cp.o cpbuild.o cpfuncts.o cpinput.o
- cc -o cp cp.o cpbuild.o cpfuncts.o cpinput.o
-
- cp.o : $H cp.c
- cc -c cp.c
-
- cpbuild.o : $H cpbuild.c
- cc -c cpbuild.c
-
- cpfuncts.o : $H cpfuncts.c
- cc -c cpfuncts.c
-
- cpinput.o : $H cpinput.c
- cc -c cpinput.c
-
-
- [LISTING THREE]
-
- #define MSDOS 0 /* Set the appropriate constant */
- #define VMS 0 /* to one (1) before compiling. */
- #define UNIX 1 /* All others are zero (0) */
-
-
- [LISTING FOUR]
-
- #if VMS
- extern int binary_search_sorted_data_base( char * );
- extern void build_box_parts( int );
- extern int build_the_data_base( char * );
- extern void check_for_new_page( void );
- extern int doprint( int );
- extern void nasty( int );
- extern void process_arguments( int, int, char **, int );
- extern void scan_for_static_or_global( int *, int, char *, char * );
- extern void tab_to_left_margin( FILE * );
-
- static void allocate_arrays( void );
- static void build_records_from_list( FILE * );
- static void bump_line_count( void );
- static void count_all_defined_references( void );
- static void deallocate_arrays( void );
- static void do_top_of_page( void );
- static void initialize_globals( void );
- static void show_files_leading_comments( void );
- static void show_function_relationships( void );
- static void show_library_functions( void );
- static void show_line_and_byte_counts( void );
- static void show_page_references( void );
- static void show_sorted_function_list( void );
- static void show_unused_if_any( void );
- static void sort_the_data_base_array( void );
- static char* strdup( char * );
- static void timedate( char * );
- int main( int, char ** );
- #endif
-
- #if MSDOS
- extern int near binary_search_sorted_data_base( char * );
- extern void near build_box_parts( int );
- extern int near build_the_data_base( char * );
- extern void near check_for_new_page( void );
- extern int near doprint( int );
- extern void near nasty( int );
- extern void near process_arguments( int, int, char **, int );
- extern void near scan_for_static_or_global( int *, int, char *, char * );
- extern void near tab_to_left_margin( FILE * );
-
- static void near allocate_arrays( void );
- static void near build_records_from_list( FILE * );
- static void near bump_line_count( void );
- static void near count_all_defined_references( void );
- static void near deallocate_arrays( void );
- static void near do_top_of_page( void );
- static void near initialize_globals( void );
- static void near show_files_leading_comments( void );
- static void near show_function_relationships( void );
- static void near show_library_functions( void );
- static void near show_line_and_byte_counts( void );
- static void near show_page_references( void );
- static void near show_sorted_function_list( void );
- static void near show_unused_if_any( void );
- static void near sort_the_data_base_array( void );
- static char* near strdup( char * );
- static void near timedate( char * );
- int near main( int, char ** );
- #endif
-
-
-
- [LISTING FIVE]
-
- #if MSDOS
- static void near bump_line_count( )
- #else
- static void bump_line_count( )
- #endif
-
-
- [LISTING SIX]
-
- #if MSDOS
- #include <malloc.h>
- #include <conio.h>
- #include <stdlib.h>
- #endif
-
- #include <ctype.h> /* this is for the 'tolower' function */
- #include <stdio.h>
- #include <string.h>
-
-
-
- [LISTING SEVEN]
-
- #if MSDOS
- #include "time.h"
- #else
- #include <time.h>
- #endif
-
-
- [LISTING EIGHT]
-
- #if !MSDOS
- char *strdup(orig)
- char *orig;
- {
- char *ptr;
-
- ptr = (char *) malloc( (strlen(orig) * sizeof(char)) + 1);
-
- if(ptr != NULL)
- {
- strcpy(ptr,orig);
- }
-
- return(ptr);
- }
- #endif
-
-
- [LISTING NINE]
-
- timedate(title);
-
-
- [LISTING TEN]
-
- /************************************************************/
- #if !MSDOS
- static void timedate(ret_time)
- char *ret_time;
- {
- struct tm *time_structure;
- int time_val, i;
- static char *hour[2] = {"am","pm"};
- char temp[19];
-
- time(&time_val);
- time_structure = localtime(&time_val);
-
- i = 0;
- if((time_structure->tm_hour >= 12)&&(time_structure->tm_hour<24)) i=1;
-
- if(time_structure->tm_hour > 12)
- time_structure->tm_hour = (time_structure->tm_hour)-12;
- sprintf(temp,"%d/%d/%d %d:%02d %s",
- time_structure->tm_mon,
- time_structure->tm_mday,
- time_structure->tm_year,
- time_structure->tm_hour,
- time_structure->tm_min,
- hour[i]);
- i=0;
- while(temp[i]!='\0')
- {
- ret_time[i] = temp[i];
- i++;
- }
- }
- #endif
-
- #if MSDOS
- static void near timedate(ret_time)
- char *ret_time;
- {
- char *cp;
- int i;
-
- cp = &ret_time[ 0 ]; /* insert date and nice time into ret_time */
- (void)_strdate( cp );
- ret_time[ 8 ] = ' ';
- cp = &ret_time[ 10 ];
- (void)_strtime( cp );
-
- ret_time[ 15 ] = ' '; /* knock off seconds */
- ret_time[ 16 ] = ' '; /* put am, pm here */
- ret_time[ 17 ] = 'm';
- ret_time[ 18 ] = ' ';
-
- i = atoi( &ret_time[ 10 ] ); /* f/ military to civilian time */
- ret_time[ 16 ] = ( i < 12 )? (char)'a': (char)'p';
-
- if( i == 0 )
- i = 12;
- if( i >= 13 )
- i -= 12;
-
- (void)sprintf( &ret_time[ 10 ], "%2d", i );
- ret_time[ 12 ] = ':';
-
- if( ret_time[ 10 ] == '0' )
- ret_time[ 10 ] = ' ';
- }
- #endif
-
- /************************************************************/
-
-
- [LISTING ELEVEN]
-
- if(islower((int)argv[i][1]))
- c = argv[i][1];
- else
- c = (char)tolower( (int)argv[ i ][ 1 ] );
-
-
- [LISTING TWELVE]
-
- if( strcmp(argv[2],"con") == 0)
- output = stderr;
- else
- output = fopen( argv[ 2 ], "w+" ); /******* wt+ <<<<<<<< ******/
-
-
- [LISTING THIRTEEN]
-
- (void)printf( "\n can't open output file.\n");
-
-
- [LISTING FOURTEEN]
-
- if( (length > 65535) && (MSDOS) )
-
-
- [LISTING FIFTEEN]
-
- $ CC/PREPROCESS_ONLY CP.C
- $ CC/PREPROCESS_ONLY CPBUILD.C
- $ CC/PREPROCESS_ONLY CPINPUT.C
- $ CC/PREPROCESS_ONLY CPFUNCTS.C
- $ CC/PREPROCESS_ONLY CPHEADER.H
-
- [LISTING SIXTEEN]
-
- cc -E cp.c >cp.i
- cc -E cpbuild.c >cpbuild.i
- cc -E cpinput.c >cpinput.i
- cc -E cpfuncts.c >cpfuncts.i
- cc -E cpheader.h >cpheader.i
-
- [LISTING SEVENTEEN]
-
- cp.i
- cpinput.i
- cpbuild.i
- cpfuncts.i
- cpheader.h
-
-
-
- [LISTING EIGHTEEN]
-
- #define LEN_INFILE 256
-
-
-
-
- [LISTING NINETEEN]
-
- char input_list_filename[ LEN_INFILE ], input_line[ LEN_INFILE ];
- char overlay_number[ LEN_INFILE ];
-
-
- [LISTING TWENTY]
-
- fgets( input_line, LEN_INFILE-1, stream ); /* ends at \n or eof */
-
-
- [LISTING TWENTY-ONE]
-
- Replaces line 20 of Listing Five
-
- *top_line_of_box, *bottom_line_of_box,
-
-
- [LISTING TWENTY-TWO]
-
- Replaces lines 73 thru 75 of Listing Five
-
- if( !( top_line_of_box =(char *)malloc( defined_box_width * sizeof(char) ))
- )
- {
- (void)fprintf( stderr, "Ran out of memory for top line of box.\n" );
- exit( 1 );
- }
-
- if( !( bottom_line_of_box =(char *)malloc( defined_box_width * sizeof(char) ))
- )
- {
- (void)fprintf( stderr, "Ran out of memory for bottom line of box.\n" );
- exit( 1 );
- }
-
- top_line_of_box[ 0 ] = upper_left_corner;
- bottom_line_of_box[ 0 ] = lower_left_corner;
- for( i = 1; i <= (defined_box_width - 3); ++i )
-
-
- [LISTING TWENTY-THREE]
-
- Replaces lines 215 and 216 of Listing Five
-
- name_of_file,
- description,
-
-
-
- [LISTING TWENTY-FOUR]
-
- Replaces lines 228 thru 274 of Listing Five
-
- unsigned int string_length;
- int x;
- static char alternate_lead_in[ 140 ];
-
- /******* 1st line *****************************************************/
- tab_to_left_margin( output );
- (void)fprintf( output, "%s %s\n", lead_in_string, top_line_of_box );
-
- /******* 2nd line ******************************************************/
- tab_to_left_margin( output );
- string_length = strlen( lead_in_string );
- if( string_length ) /******* ie not main or defined function box ***/
- {
- (void)strncpy( alternate_lead_in, lead_in_string, --string_length );
- alternate_lead_in[ string_length++ ] = '\0'; /*restore string_length*/
- }
- if( string_length ) /******* ie not main or defined function box ***/
- {
- if( g_ov_flag && ov_num )
- {
- (void)fprintf( output, "%s%c%c%c%s %3d",
- alternate_lead_in,
- /*** if( kill_flag ) /****** last line to this box ******************/
- /*** else /****** line continues downwards ***************/
- ( kill_flag )? lower_left_corner: right_attach,
- ibm_line, left_attach, name_of_function, ov_num);
- for(x=strlen(name_of_function);x < defined_box_width-7;x++)
- putc(' ',output);
- putc(wall,output);
- putc('\n',output);
- }
- else
- {
- (void)fprintf( output, "%s%c%c%c%s ",
- alternate_lead_in,
- /*** if( kill_flag ) /****** last line to this box ******************/
- /*** else /****** line continues downwards ***************/
- ( kill_flag )? lower_left_corner: right_attach,
- ibm_line, left_attach, name_of_function);
- for(x=strlen(name_of_function);x < defined_box_width-7;x++)
- putc(' ',output);
- putc(wall,output);
- putc('\n',output);
- }
- }
- else /****** main or defined box starting ***********/
- {
- if( g_ov_flag && ov_num )
- {
- (void)fprintf( output, "%c%c%s %3d",
- ibm_line, left_attach, name_of_function, ov_num);
- for(x=strlen(name_of_function);x < defined_box_width-7;x++)
- putc(' ',output);
- putc(wall,output);
- putc('\n',output);
- }
- else
- {
- (void)fprintf( output, "%c%c%s ",
- ibm_line, left_attach, name_of_function);
- for(x=strlen(name_of_function);x < defined_box_width-7;x++)
- putc(' ',output);
- putc(wall,output);
- putc('\n',output);
- }
- }
- /******* 3rd line *****************************************************/
- tab_to_left_margin( output );
- if( string_length-- ) /** kill outside vertical line on last box **/
- lead_in_string[ string_length++ ] = ( kill_flag )? (char)' ': wall;
- (void)fprintf( output, "%s %c%s %8s%3d",
- lead_in_string, wall, name_of_file, description, either_count);
- for(x=strlen(name_of_file);x < defined_box_width-17;x++) putc(' ',output);
- putc(wall,output);
- putc('\n',output);
-
-
- [LISTING TWENTY-FIVE]
-
- Insert between 109 and 110 of Listing One
-
- defined_box_width = 40,
-
-
- [LISTING TWENTY-SIX]
-
- Insert between 160 and 161 of Listing One
-
- extern int defined_box_width;
-
-
- [LISTING TWENTY-SEVEN]
-
- Replaces lines 20 through 25 of Listing Three
-
- " /p:nn /w:nn /m:nn /r:nn /t:main /f:nnnn /b:nn\n"
- );
- (void)printf(
- " /l /n /s /q /d /o /u /c /h /x\n"
- );
- (void)printf( " ]\n" );
-
-
-
- [LISTING TWENTY-EIGHT]
-
- Insert between 45 and 46 of Listing Three
-
- (void)printf(
- " b: width of func. box = %2d [ 20 - 255 ]\n", defined_box_width
- );
-
-
- [LISTING TWENTY-NINE]
-
- Insert between 155 and 156 of Listing Three
-
-
- case 'b':
- if( ( 20 < tmp ) && ( tmp < 255 ) )
- defined_box_width = tmp;
- break;
-
-
-
-
-